package com.nuoniu.sibanyun.service.erp.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.erp.ErpFile;
import com.nuoniu.sibanyun.mapper.erp.ErpFileMapper;
import com.nuoniu.sibanyun.service.erp.IErpFileService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 文件管理 服务实现类
 * </p>
 *
 * @author 小啊刚
 * @since 2021-10-26
 */
@Service
public class ErpFileServiceImpl extends ServiceImpl<ErpFileMapper, ErpFile> implements IErpFileService {

    @Override
    public List<ErpFile> getList(Integer projectId, Integer type) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("project_id", projectId);
        wrapper.eq("type", type);
        return list(wrapper);
    }

    @Override
    public void saveFile(ErpFile file) {
        if(file.getId() == null) {
            UserInfo userInfo = UserThreadLocal.get();
            file.setCreateUserId(userInfo.getUserId());
            file.setCreateUserName(userInfo.getRealName());
        }

        saveOrUpdate(file);
    }
}
